package com.springboot.test.web.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.test.common.enums.StaticKey;
import com.springboot.test.common.response.Response;
import com.springboot.test.service.MessageService;
import com.springboot.test.service.param.pageparam.BasePageParam;
import com.springboot.test.service.result.MessageDetailResult;
import com.springboot.test.service.result.MessageResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("app/message")
public class MessageController {
    @Resource
    private MessageService messageService;

    @GetMapping("count")
    public Response<Integer> messageCount(@RequestAttribute(StaticKey.USER_CODE)String userCode){
        return Response.success(messageService.messageCount(userCode));
    }

    @PostMapping("page")
    public Response<Page<MessageResult>> page(@RequestBody BasePageParam param, @RequestAttribute(StaticKey.USER_CODE)String userCode){
        return Response.success(messageService.messagePage(param,userCode));
    }

    @GetMapping("readAll")
    public Response<Boolean> readAll(@RequestAttribute(StaticKey.USER_CODE)String userCode){
        return Response.success(messageService.readAll(userCode));
    }

    @GetMapping("detail")
    public Response<MessageDetailResult> detail(String messageCode){
        return Response.success(messageService.detail(messageCode));
    }

}
